<?php
	
	require_once("nusoap/nusoap.php");
	class CampaignSoap{
    	var $proxy;
        var $sess;
		
		var $totalRows;
		
        function CampaignSoap(){
		
			$this->proxy = $_SESSION["sugar_soap_proxy"];
			$this->sess = $_SESSION["sugar_session_id"];
			$this->recordCount = 0;
			
        }
				
				
		function getRows($query, $startIndex, $numberOfRows, $orderBy=' campaigns.date_modified desc', $includeDeleted){
		
			$recordCount = 0;
		
    		$result = $this->proxy->get_entry_list(
        		$this->sess,
        		'Campaigns',
        		$query,
        		$orderBy,
        		0,
        		array(
            		'id',
					'name',
					'date_entered',
            		'date_modified',
            		'modified_user_id',
					'created_by',
					'assigned_user_id',
					'tracker_key',
					'tracker_count',
					'refer_url',
					'tracker_text',
					'start_date',
					'end_date',
					'status',
					'impressions',
					'currency_id',
					'budget',
					'expected_cost',
					'actual_code',
					'expected_revenue',
					'campaign_type',
					'objective',
					'content',
					'frequency',
					'deleted'
        		),
        		0,
        		false
    		);
			
			$returnList = array();
			
			if ($result != "" && count($result) > 0) {
			
				foreach ($result['entry_list'] as $record) {
					$returnList[] = $record;
				}
			}
			
			if ($includeDeleted) {
				
			
				if ($deleteNumberOfRows != -1) {
					$deleteResult = $this->getDeletedRows($query, 0, 0, $orderBy);
					
					if ($deleteResult != "" && count($deleteResult) > 0) {
					
						foreach ($deleteResult['entry_list'] as $record) {
							$returnList[] = $record;
						}
					}
					
				}
			} 
			
			$this->recordCount = count($returnList);
			
			if ($numberOfRows > 0)
				$returnList = array_slice($returnList, $startIndex, $numberOfRows);
			
    		return $returnList;
		}
		
		function getTotalRows() {
		
			return $this->recordCount;
	
		}
		
		function getDeletedRows($query, $startIndex, $numberOfRows, $orderBy=' campaigns.date_modified desc'){
    		$result = $this->proxy->get_entry_list(
        		$this->sess,
        		'Campaigns',
        		$query,
        		$orderBy,
        		$startIndex,
        		array(
            		'id',
					'name',
					'date_entered',
            		'date_modified',
            		'modified_user_id',
					'created_by',
					'assigned_user_id',
					'tracker_key',
					'tracker_count',
					'refer_url',
					'tracker_text',
					'start_date',
					'end_date',
					'status',
					'impressions',
					'currency_id',
					'budget',
					'expected_cost',
					'actual_cost',
					'expected_revenue',
					'campaign_type',
					'objective',
					'content',
					'frequency',
					'deleted'
        		),
        		$numberOfRows,
        		true
    		);
			
    		return $result;
		}
		
		
		function save($id, $name, $date_entered, $date_modified, $modified_user_id,
					$created_by, $assigned_user_id, $tracker_key, $tracker_count, 
					$refer_url, $tracker_text, $start_date, $end_date, $status, $impressions,
					$currency_id, $budget, $expected_cost, $actual_code, $expected_revenue, 
					$campaign_type, $objective, $content, $frequency) {
		
		
			if ($id) {
				$response = $this->proxy->set_entry($this->sess, 'Capaigns', 
								array(array("name" => 'id',"value" => $id),
									  array("name" => 'name',"value" => $photo_c),
									  array("name" => 'date_entered',"value" => $date_entered),
								      array("name" => 'date_modified',"value" => $date_modified),
            					      array("name" => 'modified_user_id',"value" => $modified_user_id),
									  array("name" => 'created_by',"value" => $created_by),
									  array("name" => 'assigned_user_id',"value" => $assigned_user_id),
									  array("name" => 'tracker_key',"value" => $tracker_key),
									  array("name" => 'tracker_count',"value" => $tracker_count),
									  array("name" => 'refer_url',"value" => $refer_url),
									  array("name" => 'tacker_text',"value" => $tracker_text),
									  array("name" => 'start_date',"value" => $start_date),
									  array("name" => 'end_date',"value" => $end_date),
									  array("name" => 'status',"value" => $status),
									  array("name" => 'impressions',"value" => $impressions),
									  array("name" => 'currency_id',"value" => $currency_id),
									  array("name" => 'budget',"value" => $budget),
									  array("name" => 'expected_cost',"value" => $expected_cost),
									  array("name" => 'actual_cost',"value" => $actual_cost),
									  array("name" => 'expected_revenue',"value" => $expected_revenue),
									  array("name" => 'campaign_type',"value" => $campaign_type),
									  array("name" => 'objective',"value" => $objective),
									  array("name" => 'content',"value" => $content),
									  array("name" => 'frequency',"value" => $frequency)
									  
            						 )
            				);
			} else {
				$response = $this->proxy->set_entry($this->sess, 'Campaigns', 
								array(array("name" => 'name',"value" => $photo_c),
									  array("name" => 'date_entered',"value" => $date_entered),
								      array("name" => 'date_modified',"value" => $date_modified),
            					      array("name" => 'modified_user_id',"value" => $modified_user_id),
									  array("name" => 'created_by',"value" => $created_by),
									  array("name" => 'assigned_user_id',"value" => $assigned_user_id),
									  array("name" => 'tracker_key',"value" => $tracker_key),
									  array("name" => 'tracker_count',"value" => $tracker_count),
									  array("name" => 'refer_url',"value" => $refer_url),
									  array("name" => 'tacker_text',"value" => $tracker_text),
									  array("name" => 'start_date',"value" => $start_date),
									  array("name" => 'end_date',"value" => $end_date),
									  array("name" => 'status',"value" => $status),
									  array("name" => 'impressions',"value" => $impressions),
									  array("name" => 'currency_id',"value" => $currency_id),
									  array("name" => 'budget',"value" => $budget),
									  array("name" => 'expected_cost',"value" => $expected_cost),
									  array("name" => 'actual_cost',"value" => $actual_cost),
									  array("name" => 'expected_revenue',"value" => $expected_revenue),
									  array("name" => 'campaign_type',"value" => $campaign_type),
									  array("name" => 'objective',"value" => $objective),
									  array("name" => 'content',"value" => $content),
									  array("name" => 'frequency',"value" => $frequency)
									  )
            			);
            }				 
			return $response;
		}
		
		function delete($id) {
		
			$response = $this->proxy->set_entry($this->sess, 'Campaigns', 
								array(array("name" => 'id',"value" => $id),
									  array("name" => 'deleted',"value" => 1),
            						 )
            				);
		
			return $response;
		
		}
		
		function nameValuePairToSimpleArray($array){
    		$my_array=array();
    		while(list($name,$value)=each($array)){
        		$my_array[$value['name']]=$value['value'];
    		}
    		return $my_array;
		} 
		
		
	}
	
$campaignSoap = new CampaignSoap();

$statusArray = array ("" => "",
					  "Planning" => "Planning",
					  "Active" => "Active",
					  "Inactive" => "Inactive",
					  "Complete" => "Complete",
					  "In Queue" => "In Queue",
					  "Sending" => "Sending");
					  
$campaignTypeArray = array ("" => "",
							"Telesales" => "Telesales",
							"Mail" => "Mail",
							"EMail" => "Email",
							"Print" => "Print",
							"Web" => "Web",
							"Radio" => "Radio",
							"Television" => "Television",
							"Newsletter" => "Newsletter");
							
$currencyArray = array ("-99" => "US Dollars : $");
						  
?>